package com.azdebugit.result.common;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;

public class ResultDTO<T> implements Serializable {
    @JsonProperty(
        index = 10
    )
    @ApiModelProperty(
        position = 10
    )
    private String code;
    @JsonProperty(
        index = 20
    )
    @ApiModelProperty(
        position = 20
    )
    private String msg;
    @JsonProperty(
        index = 30
    )
    @ApiModelProperty(
        position = 30
    )
    private String traceId;
    @JsonProperty(
        index = 40
    )
    @ApiModelProperty(
        position = 40
    )
    private T data;

    public ResultDTO() {
    }

    public ResultDTO(String code) {
        this.code = code;
    }

    public ResultDTO(String code, String msg) {
        this.code = code;
        this.msg = msg;
        this.traceId = ExtraParamUtil.getExtraParam().getTraceId();
    }

    public ResultDTO(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.traceId = ExtraParamUtil.getExtraParam().getTraceId();
    }

    public static <T> ResultDTO ok() {
        ResultDTO dto = new ResultDTO();
        dto.code = "000000";
        dto.msg = "Success";
        dto.traceId = ExtraParamUtil.getExtraParam().getTraceId();
        return dto;
    }

    public static <T> ResultDTO ok(T data) {
        ResultDTO dto = new ResultDTO();
        dto.code = "000000";
        dto.msg = "Success";
        dto.data = data;
        dto.traceId = ExtraParamUtil.getExtraParam().getTraceId();
        return dto;
    }

    public static <T> ResultDTO ok(String code, String msg, T data) {
        ResultDTO dto = new ResultDTO();
        dto.code = code;
        dto.msg = msg;
        dto.data = data;
        dto.traceId = ExtraParamUtil.getExtraParam().getTraceId();
        return dto;
    }

    public static <T> ResultDTO error() {
        return error("500", "未知异常，请联系管理员");
    }

    public static <T> ResultDTO error(String msg) {
        return error("500", msg);
    }

    public static <T> ResultDTO error(String code, String msg) {
        ResultDTO dto = new ResultDTO();
        dto.code = code;
        dto.msg = msg;
        dto.traceId = ExtraParamUtil.getExtraParam().getTraceId();
        return dto;
    }

    public String toSimpleJson() {
        return "{code='" + this.code + '\'' + ", msg='" + this.msg + '\'' + "}";
    }

    public String getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public String getTraceId() {
        return this.traceId;
    }

    public T getData() {
        return this.data;
    }

    @JsonProperty(
        index = 10
    )
    public void setCode(String code) {
        this.code = code;
    }

    @JsonProperty(
        index = 20
    )
    public void setMsg(String msg) {
        this.msg = msg;
    }

    @JsonProperty(
        index = 30
    )
    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

    @JsonProperty(
        index = 40
    )
    public void setData(T data) {
        this.data = data;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof ResultDTO)) {
            return false;
        } else {
            ResultDTO<?> other = (ResultDTO)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                label59: {
                    Object this$code = this.getCode();
                    Object other$code = other.getCode();
                    if (this$code == null) {
                        if (other$code == null) {
                            break label59;
                        }
                    } else if (this$code.equals(other$code)) {
                        break label59;
                    }

                    return false;
                }

                Object this$msg = this.getMsg();
                Object other$msg = other.getMsg();
                if (this$msg == null) {
                    if (other$msg != null) {
                        return false;
                    }
                } else if (!this$msg.equals(other$msg)) {
                    return false;
                }

                Object this$traceId = this.getTraceId();
                Object other$traceId = other.getTraceId();
                if (this$traceId == null) {
                    if (other$traceId != null) {
                        return false;
                    }
                } else if (!this$traceId.equals(other$traceId)) {
                    return false;
                }

                Object this$data = this.getData();
                Object other$data = other.getData();
                if (this$data == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$data.equals(other$data)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof ResultDTO;
    }

    /*@Override
    public int hashCode() {
        boolean PRIME = true;
        int result = 1;
        Object $code = this.getCode();
        int result = result * 59 + ($code == null ? 43 : $code.hashCode());
        Object $msg = this.getMsg();
        result = result * 59 + ($msg == null ? 43 : $msg.hashCode());
        Object $traceId = this.getTraceId();
        result = result * 59 + ($traceId == null ? 43 : $traceId.hashCode());
        Object $data = this.getData();
        result = result * 59 + ($data == null ? 43 : $data.hashCode());
        return result;
    }

    public String toString() {
        return "ResultDTO(code=" + this.getCode() + ", msg=" + this.getMsg() + ", traceId=" + this.getTraceId() + ", data=" + this.getData() + ")";
    }*/
}